package com.mallcai.bigdata.ladon.dpl.mapper.peekdata;

import com.mallcai.bigdata.ladon.dpl.entity.peekdata.PeekField;
import com.mallcai.bigdata.ladon.dpl.mapper.peekdata.provider.PeekFieldSqlProvider;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

import static com.mallcai.bigdata.ladon.dpl.mapper.peekdata.provider.PeekFieldSqlProvider.TB_PEEK_FIELD;

/**
 * @author feixy
 * @version 1.0
 * @date 2019-07-08 17:02
 */
@Repository
public interface PeekFieldMapper {

    @InsertProvider(type = PeekFieldSqlProvider.class, method = "insert")
    int insert(PeekField peekField);

    @UpdateProvider(type = PeekFieldSqlProvider.class, method = "update")
    int update(PeekField peekField);

    @Update({
            "UPDATE " + TB_PEEK_FIELD + " SET archive = 1, modified = unix_timestamp(now()), modified_by=#{modifiedBy} WHERE id = #{id}"
    })
    int deleteById(@Param("id") Long id, @Param("modifiedBy") Long userId);

    @Update({
            "UPDATE " + TB_PEEK_FIELD + " SET archive = 1, modified = unix_timestamp(now()), modified_by=#{modifiedBy} WHERE peek_id = #{peekId}"
    })
    int deleteByPeekId(@Param("peekId") Long peekId, @Param("modifiedBy") Long userId);

    @SelectProvider(type = PeekFieldSqlProvider.class, method = "getByPeekId")
    List<PeekField> getByPeekId(@Param("peekId") Long peekId);
}
